package com.chinaisafe.gateway.exception;

import cn.dev33.satoken.exception.SaTokenException;
import com.chinaisafe.base.common.vo.Answer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * LoginCheckOutputVo
 * Description：
 *
 * @author xuefu.shu
 * @date 2024/7/5 14:13
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * saToken异常拦截
     * @param saxException saToken异常信息
     * @return Answer
     */
    @ExceptionHandler(SaTokenException.class)
    public Answer oauth2Exception(SaTokenException saxException) {
        return Answer.fail(saxException.getMessage());
    }

    /**
     * 全局异常拦截
     * @param e 异常信息
     * @return Answer
     */
    @ExceptionHandler(Exception.class)
    public Answer handlerException(Exception e) {
        log.error("[全局异常拦截] 异常信息:"+ e.getMessage(), e);
        return Answer.fail("服务器网络开小差了");
    }

}
